package xin.infinite.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import xin.infinite.mapper.UserMapper;
import xin.infinite.pojo.User;

import java.util.Date;

/**
 * @author shkstart
 * @Date 2020/6/11 0011 - 15:32
 */

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper  userMapper;


    @Override
    public boolean findUserByUP(String username, String password) {
        String md5pass= DigestUtils.md5DigestAsHex(password.getBytes());
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.eq("username",username).eq("password",md5pass);
        User user=userMapper.selectOne(queryWrapper);
       if(user!=null) {
           return true;
       }else{
           return false;
       }
    }

    @Override
    public void doSave(User user) {
        String md5pass= DigestUtils.md5DigestAsHex(user.getPassword().getBytes());
        user.setPassword(md5pass).setCreatedTime(new Date()).setUpdateTime(user.getCreatedTime());
        userMapper.insert(user);
    }
}
